<?php

/**
 * /	手动记录重要信息
 * @return [null]
 */
function saveLog($message = '')
{
    $log = fopen("log.txt", "a");
    $txt = date('Y-m-d H:i:s',time()).' : '.$message."\n";
    fputs($log, $txt);
    fclose($log);
}

/**
 * /	格式化打印
 * @return [$data]
 */
function vard($message = '')
{
    echo '<pre>';
    var_dump($message);die;
}

/**
 * /	接口处理成功返回
 * @return [json]
 */
function success($data = array(),$message = '处理成功')
{
    $data['status'] = 1;
    $data['message'] = $message;
    $data['userInfo'] = cache($_SESSION['token']['value']);
    echo json_encode($data);
    exit();
}

/**
 * /	接口处理失败返回
 * @return [json]
 */
function error($message = '处理失败')
{
    $data['status'] = 0;
    $data['message'] = $message;
    if ($message == 'login'){
        $data['status'] = 2;
        $data['message'] = '登录超时,请重新登录';
    }
    echo json_encode($data);
    exit();
}

/**
 * /	数据库查询操作
 * @return [data]
 */
function getData($sql)
{
    return \think\facade\Db::query($sql);
}

/**
 * /	变量自带引号
 * @return [data]
 */
function marks($data)
{
    return "'".$data."'";
}

/**
 * /	访问用户自生成独立token
 * @return [data]
 */
function createToken()
{
    return md5(get_os().browse_info().get_lang().$_SERVER["REMOTE_ADDR"].time());
}

/**
 * /	获得访客操作系统
 * @return [data]
 */
function get_os()
{
    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
        $os = $_SERVER['HTTP_USER_AGENT'];
        if (preg_match('/win/i', $os)) {
            $os = 'Windows';
        } else if (preg_match('/mac/i', $os)) {
            $os = 'MAC';
        } else if (preg_match('/linux/i', $os)) {
            $os = 'Linux';
        } else if (preg_match('/unix/i', $os)) {
            $os = 'Unix';
        } else if (preg_match('/bsd/i', $os)) {
            $os = 'BSD';
        } else {
            $os = 'Other';
        }
        return $os;
    } else {
        return 'unknow';
    }
}

/**
 * /	生成订单编号
 * @return [data]
 */
function ordercode($id = 0)
{
    //生成时间序号
    $time = date('Ymd',time());
    $num = str_pad($id,6,"0",STR_PAD_LEFT);
    return $time . $num;
}

/**
 * /	获得访问者浏览器
 * @return [data]
 */
function browse_info()
{
    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
        $br = $_SERVER['HTTP_USER_AGENT'];
        if (preg_match('/MSIE/i', $br)) {
            $br = 'MSIE';
        } else if (preg_match('/Firefox/i', $br)) {
            $br = 'Firefox';
        } else if (preg_match('/Chrome/i', $br)) {
            $br = 'Chrome';
        } else if (preg_match('/Safari/i', $br)) {
            $br = 'Safari';
        } else if (preg_match('/Opera/i', $br)) {
            $br = 'Opera';
        } else {
            $br = 'Other';
        }
        return $br;
    } else {
        return 'unknow';
    }
}

/**
 * /	获得访问者浏览器语言
 * @return [data]
 */
function get_lang()
{
    if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
        $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
        $lang = substr($lang, 0, 5);
        if (preg_match('/zh-cn/i',$lang)) {
            $lang = '简体中文';
        } else if (preg_match('/zh/i',$lang)) {
            $lang = '繁体中文';
        } else {
            $lang = 'English';
        }
        return $lang;
    } else {
        return 'unknow';
    }
}

//二维数组去掉重复值  并保留键值
function array_unique_fb($array2D,$key)
{
    foreach ($array2D as $k=>$v)
    {
        $v = join(",",$v);  //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
        $temp[$k] = $v;
    }
    $temp = array_unique($temp);    //去掉重复的字符串,也就是重复的一维数组
    foreach ($temp as $k => $v)
    {
        $array=explode(",",$v);		//再将拆开的数组重新组装
        for ($i = 0; $i< count($key); $i++){
            $temp2[$k][$key[$i]] = $array[$i];
        }
    }
    return $temp2;
}


/**
 * /    权限列表
 * @return [data]
 */
function jurisdiction()
{
    return array(
        0 => array(
            'id' => 1,
            'pid' => 0,
            'title' => '企业首页'
        ),
        1 => array(
            'id' => 2,
            'pid' => 0,
            'title' => '业务管理'
        ),
        2 => array(
            'id' => 3,
            'pid' => 0,
            'title' => '项目任务管理'
        ),
        3 => array(
            'id' => 4,
            'pid' => 0,
            'title' => '业绩奖金'
        ),
        4 => array(
            'id' => 5,
            'pid' => 0,
            'title' => '人事资料'
        ),
        5 => array(
            'id' => 6,
            'pid' => 0,
            'title' => '行政服务'
        ),
        6 => array(
            'id' => 7,
            'pid' => 0,
            'title' => '公告'
        ),
        7 => array(
            'id' => 8,
            'pid' => 0,
            'title' => '财务管理'
        ),
        8 => array(
            'id' => 9,
            'pid' => 0,
            'title' => '供应产品成本'
        ),
        9 => array(
            'id' => 10,
            'pid' => 0,
            'title' => '系统设置'
        ),
        10 => array(
            'id' => 11,
            'pid' => 2,
            'title' => '咨询线索'
        ),
        11 => array(
            'id' => 12,
            'pid' => 2,
            'title' => '客户档案'
        ),
        12 => array(
            'id' => 13,
            'pid' => 2,
            'title' => '客户跟进'
        ),
        13 => array(
            'id' => 14,
            'pid' => 2,
            'title' => '项目报价'
        ),
        14 => array(
            'id' => 15,
            'pid' => 2,
            'title' => '业务收款'
        ),
        15 => array(
            'id' => 16,
            'pid' => 2,
            'title' => '发票管理'
        ),
        16 => array(
            'id' => 17,
            'pid' => 2,
            'title' => '业务合同'
        ),
        17 => array(
            'id' => 18,
            'pid' => 11,
            'title' => '增加'
        ),
        18 => array(
            'id' => 19,
            'pid' => 11,
            'title' => '修改'
        ),
        19 => array(
            'id' => 20,
            'pid' => 11,
            'title' => '删除'
        ),
        20 => array(
            'id' => 21,
            'pid' => 11,
            'title' => '导入'
        ),
        21 => array(
            'id' => 22,
            'pid' => 11,
            'title' => '查看'
        ),
        22 => array(
            'id' => 23,
            'pid' => 11,
            'title' => '报价单'
        ),
        23 => array(
            'id' => 24,
            'pid' => 12,
            'title' => '增加'
        ),
        24 => array(
            'id' => 25,
            'pid' => 12,
            'title' => '修改'
        ),
        25 => array(
            'id' => 26,
            'pid' => 12,
            'title' => '删除'
        ),
        26 => array(
            'id' => 27,
            'pid' => 12,
            'title' => '导入'
        ),
        27 => array(
            'id' => 28,
            'pid' => 12,
            'title' => '查看'
        ),
        28 => array(
            'id' => 29,
            'pid' => 12,
            'title' => '回访'
        ),
        29 => array(
            'id' => 30,
            'pid' => 13,
            'title' => '增加'
        ),
        30 => array(
            'id' => 31,
            'pid' => 13,
            'title' => '修改'
        ),
        31 => array(
            'id' => 32,
            'pid' => 13,
            'title' => '删除'
        ),
        32 => array(
            'id' => 33,
            'pid' => 13,
            'title' => '导入'
        ),
        33 => array(
            'id' => 34,
            'pid' => 13,
            'title' => '查看'
        ),
        34 => array(
            'id' => 35,
            'pid' => 13,
            'title' => '报价单'
        ),
        35 => array(
            'id' => 36,
            'pid' => 14,
            'title' => '增加'
        ),
        36 => array(
            'id' => 37,
            'pid' => 14,
            'title' => '修改'
        ),
        37 => array(
            'id' => 38,
            'pid' => 14,
            'title' => '删除'
        ),
        38 => array(
            'id' => 39,
            'pid' => 14,
            'title' => '导入'
        ),
        39 => array(
            'id' => 40,
            'pid' => 14,
            'title' => '查看'
        ),
        40 => array(
            'id' => 41,
            'pid' => 14,
            'title' => '报价单'
        ),
        41 => array(
            'id' => 42,
            'pid' => 15,
            'title' => '增加'
        ),
        42 => array(
            'id' => 43,
            'pid' => 15,
            'title' => '修改'
        ),
        43 => array(
            'id' => 44,
            'pid' => 15,
            'title' => '删除'
        ),
        44 => array(
            'id' => 45,
            'pid' => 15,
            'title' => '导入'
        ),
        45 => array(
            'id' => 46,
            'pid' => 15,
            'title' => '查看'
        ),
        46 => array(
            'id' => 47,
            'pid' => 15,
            'title' => '报价单'
        ),
        47 => array(
            'id' => 48,
            'pid' => 16,
            'title' => '增加'
        ),
        48 => array(
            'id' => 49,
            'pid' => 16,
            'title' => '修改'
        ),
        49 => array(
            'id' => 50,
            'pid' => 16,
            'title' => '删除'
        ),
        50 => array(
            'id' => 51,
            'pid' => 16,
            'title' => '导入'
        ),
        51 => array(
            'id' => 52,
            'pid' => 16,
            'title' => '查看'
        ),
        52 => array(
            'id' => 53,
            'pid' => 16,
            'title' => '报价单'
        ),
        53 => array(
            'id' => 54,
            'pid' => 17,
            'title' => '增加'
        ),
        54 => array(
            'id' => 55,
            'pid' => 17,
            'title' => '修改'
        ),
        55 => array(
            'id' => 56,
            'pid' => 17,
            'title' => '删除'
        ),
        56 => array(
            'id' => 57,
            'pid' => 17,
            'title' => '导入'
        ),
        57 => array(
            'id' => 58,
            'pid' => 17,
            'title' => '查看'
        ),
        58 => array(
            'id' => 59,
            'pid' => 17,
            'title' => '报价单'
        ),
        59 => array(
            'id' => 60,
            'pid' => 10,
            'title' => '用户列表'
        ),
        60 => array(
            'id' => 61,
            'pid' => 10,
            'title' => '部门列表'
        ),
        61 => array(
            'id' => 62,
            'pid' => 10,
            'title' => '参数配置'
        ),
        62 => array(
            'id' => 63,
            'pid' => 60,
            'title' => '增加'
        ),
        63 => array(
            'id' => 64,
            'pid' => 60,
            'title' => '修改'
        ),
        64 => array(
            'id' => 65,
            'pid' => 60,
            'title' => '删除'
        ),
        65 => array(
            'id' => 66,
            'pid' => 61,
            'title' => '增加'
        ),
        66 => array(
            'id' => 67,
            'pid' => 61,
            'title' => '修改'
        ),
        67 => array(
            'id' => 68,
            'pid' => 61,
            'title' => '删除'
        ),
        68 => array(
            'id' => 69,
            'pid' => 11,
            'title' => '分配会员'
        ),
        69 => array(
            'id' => 70,
            'pid' => 12,
            'title' => '分配会员'
        ),
//        70 => array(
//            'id' => 71,
//            'pid' => 61,
//            'title' => '修改'
//        ),
//        71 => array(
//            'id' => 72,
//            'pid' => 61,
//            'title' => '删除'
//        ),
        72 => array(
            'id' => 73,
            'pid' => 61,
            'title' => '职位权限菜单'
        ),
        73 => array(
            'id' => 74,
            'pid' => 62,
            'title' => '增加'
        ),
        74 => array(
            'id' => 75,
            'pid' => 62,
            'title' => '修改'
        ),
        75 => array(
            'id' => 76,
            'pid' => 62,
            'title' => '删除'
        ),
        76 => array(
            'id' => 77,
            'pid' => 62,
            'title' => '客户行业'
        ),
        77 => array(
            'id' => 78,
            'pid' => 62,
            'title' => '合同类型'
        ),
        78 => array(
            'id' => 79,
            'pid' => 62,
            'title' => '客户来源'
        ),
        79 => array(
            'id' => 80,
            'pid' => 62,
            'title' => '跟进阶段'
        ),
        80 => array(
            'id' => 81,
            'pid' => 62,
            'title' => '跟进方式'
        ),
        81 => array(
            'id' => 82,
            'pid' => 62,
            'title' => '支付方式'
        ),
        82 => array(
            'id' => 83,
            'pid' => 62,
            'title' => '订单状态'
        ),
        83 => array(
            'id' => 84,
            'pid' => 62,
            'title' => '发票类型'
        ),
        84 => array(
            'id' => 85,
            'pid' => 62,
            'title' => '会议室'
        ),
        85 => array(
            'id' => 86,
            'pid' => 62,
            'title' => '文件类型'
        ),
        86 => array(
            'id' => 87,
            'pid' => 62,
            'title' => '加盖何种印章'
        ),
        87 => array(
            'id' => 88,
            'pid' => 62,
            'title' => '费用申请类型'
        ),
        88 => array(
            'id' => 89,
            'pid' => 62,
            'title' => '销售部提成'
        ),
        89 => array(
            'id' => 90,
            'pid' => 62,
            'title' => '客服部提成'
        ),
        90 => array(
            'id' => 91,
            'pid' => 62,
            'title' => '客户类型'
        ),
        91 => array(
            'id' => 92,
            'pid' => 62,
            'title' => '客户类别'
        ),
        92 => array(
            'id' => 1301,
            'pid' => 13,
            'title' => '回访'
        ),
        93 => array(
            'id' => 1302,
            'pid' => 13,
            'title' => '高级搜索'
        ),
        93 => array(
            'id' => 1101,
            'pid' => 11,
            'title' => '高级搜索'
        ),
    );
}
